Unit Cube
Unit CubeΒΆ
Here we show some example of plotting the objects defined on a Unit Cube
import dolfin as df
from fenics_plotly import plot
mesh = df.UnitCubeMesh(3, 3, 3)
plot(mesh)
# plot(mesh, wireframe=False)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f404f0f2680>
for degree in [2]:
V = df.FunctionSpace(mesh, "CG", degree)
p = df.Function(V)
p.interpolate(df.Expression("sin(x[0])", degree=1))
plot(V)
plot(p, show_grid=True)
plot(p, scatter=True, wireframe=False)
Calling FFC just-in-time (JIT) compiler, this may take some time.
V = df.VectorFunctionSpace(mesh, "CG", 2)
u = df.Function(V)
u.interpolate(df.Expression(("1 + x[0]*x[0]", "x[1]*x[1]", "x[2]*x[2]") , degree=1))
plot(V)
plot(u, size=1)
#plot(u, normalize=True, size=1)
#plot(u, norm=True, size=1)
Calling FFC just-in-time (JIT) compiler, this may take some time.
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f404439ada0>
for component in ["magnitude", "x"]: #, "y", "z"]:
plot(u, component=component)
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
WARNING: The number of integration points for each cell will be: 125
Consider using the option 'quadrature_degree' to reduce the number of points
Calling FFC just-in-time (JIT) compiler, this may take some time.
fixed = df.CompiledSubDomain("near(x[0], 0) && on_boundary")
free = df.CompiledSubDomain("near(x[0], 1) && on_boundary")
# Create a facet fuction in order to mark the subdomains
ffun = df.MeshFunction("size_t", mesh, 2)
ffun.set_all(0)
# Mark the first subdomain with value 1
fixed_marker = 1
fixed.mark(ffun, fixed_marker)
# Mark the second subdomain with value 2
free_marker = 2
free.mark(ffun, free_marker)
V = df.VectorFunctionSpace(mesh, "CG", 2)
bc = df.DirichletBC(V, df.Constant((0.0, 0.0, 0.0)), fixed)
plot(bc)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f404451f3d0>
plot(ffun, show_grid=True)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f404438f8b0>
cfun = df.MeshFunction("size_t", mesh, 3)
cfun.set_all(1)
tol=1e-14
left = df.CompiledSubDomain("x[0] <= 0.5 + tol", tol=tol)
right = df.CompiledSubDomain("x[0] >= 0.5 - tol", tol=tol)
left_marker = 1
#left.mark(cfun, left_marker)
right_marker = 2
right.mark(cfun, right_marker)
plot(cfun)#, scatter=True)
Calling FFC just-in-time (JIT) compiler, this may take some time.
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f404405ed70>